import { Component, OnInit } from '@angular/core';
import { HttpRequest } from "../../service/httpRequest";
import { HideElementService } from "../../service/hideElement.service";

declare var $:any;
@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})

export class DashboardComponent implements OnInit {
  elc = {a:'产品数量',b:'设备数量',c:'用户数量',d:'故障数量'};
  num = {product:0,device:0,account:0,fault:0};
  option;

  constructor(private httpRequest:HttpRequest,private he:HideElementService) {
    this.elc = this.he.hideElement(this.elc);
  }

  ngOnInit() {
    if(localStorage.getItem("isLogin")) {
      this.getNums();
    }

  }


  //获取数量
  getNums():void{
    this.httpRequest.sendGet('products/count').subscribe(res => {
      if(res.resultStatus == 200){
        this.num['product'] = res.result.num;
      }
    },err => console.log(err));
    this.httpRequest.sendGet('devices/count').subscribe(res => {
      if(res.resultStatus == 200){
        this.num['device'] = res.result.num;
      }
    },err => console.log(err));
    this.httpRequest.sendGet('account/count').subscribe(res => {
      if(res.resultStatus == 200){
        this.num['account'] = res.result.num;
      }
    },err => console.log(err));
    this.httpRequest.sendGet('stat/guzhang/total').subscribe(res => {
      this.num['fault'] = res;
    },err => console.log(err))
    
  }











}
